package orchestration.utils;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Date;

import orchestration.android.execution.exceptions.LockException;

public class LockingUtils {

	public static String generateKey(){
		return ""+ (new Date()).getTime();
	}
	public static String encrypt(String s) throws LockException{
		 try {
		        // Create MD5 Hash
		        MessageDigest digest = java.security.MessageDigest.getInstance("MD5");
		        digest.update(s.getBytes());
		        byte messageDigest[] = digest.digest();
		        
		        // Create Hex String
		        StringBuffer hexString = new StringBuffer();
		        for (int i=0; i<messageDigest.length; i++)
		            hexString.append(Integer.toHexString(0xFF & messageDigest[i]));
		        return hexString.toString();
		        
		    } catch (NoSuchAlgorithmException e) {
		       throw new LockException(e);
		    }
	}
	
}
